<!--
 * @Descripttion:
 * @version:
 * @Author: zhuzm@linkstec.com
 * @Date: 2023-03-24 16:53:04
 * @LastEditors: sueRimn
 * @LastEditTime: 2023-03-24 17:01:54
-->
<!--
 * @Descripttion:
 * @version:
 * @Author: zhuzm@linkstec.com
 * @Date: 2023-02-07 10:15:43
 * @LastEditors: sueRimn
 * @LastEditTime: 2023-03-20 10:48:16
-->
<script>
export default {
  data () {
    return {
      keywords: '',
      searchType: 'all', // 搜索类型
      tableData: {
        WEALTH: {

        },
        REPORT: {

        },
        CHART: {

        },
        ACTIVITY: {

        },
        STOCK: {

        },
        AGGREGATION: {

        },
        researchData: {

        },
        bonddata: {},
        managerdata: {},
        discoverdata: {},
        publisherdata: {}
      },
      highlightKeys: ['title', 'prod_name', 'prod_code', 'stockName', 'stockCode'], // 需要高亮处理的key
      highlightCls: 'search-highlight' // 高亮类名
    };
  },
  watch: {

  },
  methods: {
    /**
     * 高亮结果
     * @param {object} data - 搜索结果
     * @param {object} type - 类型 产品:product
     * @param {string} keywords - 要高亮的关键词
     * @param {array} keys - 要高亮的键名
     */
    highlightData (data, keywords, keys) {
      const result = {};
      data.forEach(item => {
        const dataObj = {};
        dataObj.totalCount = item.totalCount;
        dataObj.typeName = item.typeName;
        if (item.list && item.list.length > 0) {
          dataObj.list = item.list.map(box => {
            keys.forEach(key => {
              if (box.hasOwnProperty(key) && keywords) {
                box[key + '_v'] = String(box[key]).replaceAll(keywords, `<span class="${this.highlightCls}">${keywords}</span>`);
              }
            });
            return {
              ...box
            };
          });
        } else {
          dataObj.list = [];
        }
        result[item.targetType] = dataObj;
      });
      return result;
    }
  }
};
</script>
